<?php
/**
 * <i>@assert</i>组件
 * 
 * 可以使用的参数有
 * - x-assertion string 断言，可以使用很简单的PHP语法，如
 * <code>
 * <span com="@assert" x-assertion="count($array)>2">
 * under assertion
 * </span>
 * </code> 
 * 
 * @version $Id: IMintAssertComponent.php 312 2008-04-23 16:29:38Z iwind $
 * @package util.mint.component
 */
class IMintAssertComponent extends IAbstractMintComponent {
	/**
	 * 取得支持的参数列表
	 *
	 * @return array
	 */	
	public function getSupportedParameters() {
		return array("x-assertion");
	}
	
	/**
	 * 取得HTML属性映射
	 *
	 * @return array
	 * @since 0.0.3
	 */		
	public function getHtmlAttrMapping() {
		return array();
	}
	
	/**
	 * 处理组件
	 *
	 * @return boolean
	 */	
	public function processComponent() {
		$parameters = $this->getParameters();
		
		if (!isset($parameters["x-assertion"])) {
			return false;
		}
		
		$assertion = $parameters["x-assertion"];
		foreach (IMintConfig::$variableMarkArray as $mark) {
			$mark = preg_quote($mark, "/");
			$assertion = preg_replace("/({$mark})([a-z_]\\w*)/i", "\$TDataSet->\\2", $assertion);
			$assertion = preg_replace("/({$mark})\\{([a-z_]\\w*)\\}/i", "\$TDataSet->\\2", $assertion);
		}
		$beginText = "<?php if(" . $assertion . ") {?>\n";
		$endText = "<?php } ?>";
		$this->addAroundScript($beginText, $endText);
		
		return true;
	}
}

?>